package com.wu.flandre.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wu.flandre.dao.ApiCallErrorDaoMapper;
import com.wu.flandre.entity.table.ApiCallError;
import com.wu.flandre.service.ApiCallErrorService;
import com.wu.flandre.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wu
 * @since 2019-12-15
 */
@Service
public class ApiCallErrorServiceImpl extends ServiceImpl<ApiCallErrorDaoMapper, ApiCallError> implements ApiCallErrorService {

    @Autowired
    private ApiCallErrorDaoMapper apiCallErrorDaoMapper;
    @Autowired
    private CommonUtil commonUtil;

    @Override
    public void recordAopErrorLog(String logMessage, String uri) {
        ApiCallError apiCallError = new ApiCallError();
        apiCallError.setErrorLogId(commonUtil.getUUID());
        apiCallError.setErrorMessage(StringUtils.isEmpty(logMessage)?"缺少Access_Token":logMessage);
        apiCallError.setCreateTime(LocalDateTime.now());
        apiCallError.setUri(uri);
        apiCallErrorDaoMapper.insert(apiCallError);
    }
}
